﻿using Finance.Api.Write.Applications.Commands.库存盘点;
using Finance.Api.Write.Applications.Commands.入库管理;
using Finance.Api.Write.Applications.Commands.出库管理;
using Finance.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Finance.Api.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
   
    public class ChecksController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ChecksController> logger;

        public ChecksController(IMediator mediator, ILogger<ChecksController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 库存盘点添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddCheck(CheckAddCommand request)
        {
            try
            {
                logger.LogInformation("库存盘点信息添加");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("异常信息=》" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 库存盘点修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateCheck(CheckUpdateCommand request)
        {
            try
            {
                logger.LogInformation("库存盘点信息修改");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("错误信息=>" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 库存盘点删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteCheck(CheckDeleteCommand request)
        {
            try
            {
                logger.LogInformation("库存盘点信息删除");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("错误信息=>" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 库存盘点批量删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> BatchDeleteCheck(CheckBatchDeleteCommand request)
        {
            try
            {
                logger.LogInformation("库存盘点信息批量删除");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("错误信息=>" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 库存盘点状态更新
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateCheckStatus(CheckUpdateStatusCommand request)
        {
            try
            {
                logger.LogInformation("库存盘点状态更新");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("错误信息=>" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 入库信息添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddGoin(GoinAddCommand request)
        {
            try
            {
                logger.LogInformation("入库信息添加");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("异常信息=》" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 出库信息添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddOut(OutAddCommand request)
        {
            try
            {
                logger.LogInformation("出库信息添加");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("异常信息=》" + ex.Message);
                throw;
            }
        }
    }
}
